package com.bi.bitest.bao.fragments.discover;


import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.bi.bitest.bao.Constants;
import com.bi.bitest.bao.R;
import com.bi.bitest.bao.entity.DiscoverCategory;
import com.bi.bitest.bao.fragments.BaseFragment;
import com.bi.bitest.bao.tasks.DiscoverCategoryTask;
import com.bi.bitest.bao.tasks.TaskCallback;
import com.bi.bitest.bao.tasks.TaskResult;

import java.util.List;

/**
 * Created
 * Author:bi[FR]
 * Date:15-10-20
 */
public class DiscoverCategoryFragment extends BaseFragment implements TaskCallback {
    public DiscoverCategoryFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        DiscoverCategoryTask task=new DiscoverCategoryTask(this);
        task.execute();

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_discover_category, container, false);
    }

    @Override
    public String getFragmentTitle() {
        return "分类";
    }

    @Override
    public void onTaskFinished(TaskResult result) {
        if(result!=null){
            int action=result.action;
            if(action== Constants.TASK_ACTION_DISCOVER_CATEGORIES){
                if(result.retCode==Constants.TASK_RESULT_OK){
                    Object data=result.data;
                    if(data!=null&&data instanceof List){
                        List<DiscoverCategory>list=(List)data;
                        for(int i=0;i<list.size();i++)
                        Log.d("category","list->"+list.get(i).getTitle());
                    }

                }else{
                    //TODO 加载失败
                }

            }
        }
    }
}
